//https://leetcode.cn/problems/maximum-subarray/submissions/577397534/
class Solution {
public:
    int maxSubArray(vector<int>& nums) {
        int n = nums.size();
        vector<int> dp(n);
        dp[0] = nums[0];
        for (int i = 1; i < n; ++i)
        {
            dp[i] = max(dp[i - 1] + nums[i], nums[i]);
        }
        int ret = -INT_MAX;
        for (auto tmp : dp)
        {
            if (ret < tmp)
                ret = tmp;
        }
        return ret;
    }
};